<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet"/>
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link th:href="@{/erp/assets/css/codemirror.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/font/css/font-awesome.min.css}"/>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet"/>
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/Widget/zTree/css/zTreeStyle/zTreeStyle.css}" type="text/css">
    <link th:href="@{/erp/Widget/icheck/icheck.css}" rel="stylesheet" type="text/css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace-ie.min.css}"/>
    <![endif]-->
    <script th:src="@{/erp/js/jquery-1.9.1.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <script th:src="@{/erp/assets/js/typeahead-bs2.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.bootstrap.js}"></script>
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/erp/assets/laydate/laydate.js}" type="text/javascript"></script>
    <script th:src="@{/erp/js/displayPart.js}" type="text/javascript"></script>


    <title>出入库单录入</title>
</head>

<body>
<div class="margin clearfix">
    <div class="Shops_Audit">
        <!--模糊查询-->
        <div class="search_style">
            <ul class="search_content clearfix">
                <form id="search">
                    <li><label class="l_f">出/入库单号</label>
                        <input name="ioNo" id="ioNo" type="text" class="text_add" placeholder="请输入出/入库单号"
                               style=" width:180px"/>
                    </li>
                    <li><label class="l_f">批次号</label>
                        <input name="batchNo" id="batchNo" type="text" class="text_add" placeholder="请输入批次号"
                               style=" width:180px"/>
                    </li>
                    <li style="width:90px;">
                        <button type="button" class="btn_search" id="btn_search"><i class="icon-search"></i>查询</button>
                    </li>
                </form>
            </ul>
        </div>
        <!--出入库添加按钮-->
        <div class="border clearfix">
            <span class="l_f">
               <a href="javascript:void(0)" id="bu" class="btn btn-warning"><i class="icon-plus"></i>出库添加</a>
               <a href="javascript:void(0)" id="bb" class="btn btn-warning"><i class="icon-plus"></i>入库添加</a>
            </span>
        </div>
        <!--出入库列表-->
        <div class="audit_list">
            <table class="table table-striped table-bordered table-hover" id="io-table">
                <thead>
                <tr>
                    <th width="80px">序号</th>
                    <th width="80px">出/入库单号</th>
                    <th width="100">出/入库类型</th>
                    <th width="80px">批次</th>
                    <th width="70">产品名称</th>
                    <th width="70">产品数量</th>
                    <th width="80px">仓库名称</th>
                    <th width="80px">出/入库时间</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>

<!--出库添加的界面-->
<div class="add_out_menber" id="add_menber_style" style="display:none;">
    <ul class=" page-content">
        <form id="addOut">
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>出库单号：</label>
            <div class="formControls ">
                <input type="text" class="input-text" readonly id="outNo" name="ioNo">
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>出库类型：</label>
            <div class="formControls ">
                <select style="margin-left:10px;" name="ioType">
                    <option>请选择出库类型</option>
                    <option value="销售订单出库">销售订单出库</option>
                </select>
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>批次：</label>
            <div class="formControls">
                <select style="margin-left:10px;" id="outBatch" name="batch">
                    <option value="">请选择批次</option>
                </select>
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>产品名称：</label>
            <div class="formControls ">
                <input type="text" class="input-text" readonly id="productName" name="pName">
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>出库数量：</label>
            <div class="formControls ">
                <input type="text" class="input-text" readonly id="outNum" name="pNum">
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>仓库名称：</label>
            <div class="formControls">
                <select style="margin-left:10px;" id="allWarehouse" name="wName">
                    <option value="">请选择仓库</option>
                </select>
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>出库时间：</label>
            <div class="formControls ">
                <input type="text" class="inline laydate-icon" value="" id="outTime" name="ioTime">
            </div>
        </div>
        </form>
    </ul>
</div>

<!--出入库列表-->
<script>
    $(function () {
        $(".displayPart").displayPart();
    });
    $(function () {
        var ioTable = $('#io-table').dataTable({
            searching : false,  //取消本地搜索框
            serverSide: true,   //开始服务器分页
            pageLength: 10,
            ajax: {
                url : '/ioWarehouse/page',
                type : 'post',
                data : function (d) {
                    var data = $('#search').serialize();   //获取查询条件
                    //获取分页信息
                    var searchParams= {
                        start : d.start/10+1,
                        length : d.length,
                    };
                    data = data + '&' + $.param(searchParams);
                    return data;
                }
            },
            columns : [
                { "data": "ioNo",'sDefaultContent': '' , "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).text(row+1);
                    } },
                { "data": "ioNo",'sDefaultContent': '' },
                { "data": "ioType",'sDefaultContent': '' },
                { "data": "batch",'sDefaultContent': '' },
                { "data": "pname" ,'sDefaultContent': ''},
                { "data": "pnum",'sDefaultContent': '' },
                { "data": "wname" ,'sDefaultContent': ''},
                { "data": "ioTime" ,'sDefaultContent': ''},
                {"data" : "ioTime",'sDefaultContent': '', "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append('<a title="详情" class="btn btn-xs btn-info property_list"><i class="icon-list bigger-120"></i></a>');
                    }},
            ]
        })
        //搜索
        $('#btn_search').click(function () {
            ioTable.fnUpdate();
        })
    })
</script>
<!--出库添加的界面跳转-->
<script>
    $(function () {
        $("#bu").on('click', function () {
            /*按照当前的时间生成单号*/
            $('#outNo').val(new Date().getTime());
            /*出库添加中的仓库下拉框的数据*/
            $('#allWarehouse:last').empty().append("<option value=\"\">请选择仓库</option>")
            $.ajax({
                url: "[[@{/cargo/allWare}]]",
                success: function (d) {
                    if (d.rs) {
                        var data = d.data;
                        for (var i in data) {
                            $('#allWarehouse:last').append("<option value=" + data[i].id + ">" + data[i].wareName + "</option>")
                        }
                    } else {
                        layer.msg(d.msg,{icon:2,time:2000});
                    }
                }
            })
            /*出库添加中的批次下拉框的数据*/
            $('#outBatch:last').empty().append("<option value=\"\">请选择批次</option>")
            $.ajax({
                url: "[[@{/ioWarehouse/getAllBatch}]]",
                success: function (d) {
                    if (d.rs) {
                        for (var i in d.data) {
                            $('#outBatch:last').append("<option value=" + d.data[i] + ">" + d.data[i] + "</option>")
                        }
                    }else {
                        layer.msg(d.msg,{icon:2,time:2000});
                    }
                }
            })
            /*选择批次后添加对应的产品名称以及产品数量*/
            $('#outBatch').bind('change', function () {
                $.ajax({
                    url: '[[@{/ioWarehouse/getPNameByBatch}]]',
                    data: {
                        outBatchNo: $('#outBatch').val()
                    },
                    success: function (d) {
                        if (d.rs) {
                            $('#productName').val(d.data.pname);
                            $('#outNum').val(d.data.pnum);
                        } else {
                            layer.msg(d.msg,{icon:2,time:2000});
                        }
                    }
                })
            })
            layer.open({
                type: 1,
                title: '添加出库单',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['600px', ''],
                content: $('#add_menber_style'),
                btn: ['确定出库', '取消'],
                yes: function (index, layero) {
                    var num = 0;
                    var str = "";
                    $("#addOut input[type$='text']").each(function (n) {
                        if ($(this).val() == "") {
                            layer.alert(str += "" + $(this).context.parentElement.parentElement.firstElementChild.textContent.split("：",1) + "不能为空！\r\n", {
                                title: '提示框',
                                icon: 0,
                            });
                            num++;
                            return false;
                        }
                    });
                    if (num > 0) {
                        return false;
                    } else {
                        $.ajax({
                            url : '/ioWarehouse/addOut',
                            type: "post",
                            data : $('#addOut').serialize(),
                            success : function (d) {
                                if (d.rs){
                                    layer.alert('出库成功！', {
                                        title: '提示框',
                                        icon: 1,
                                    });
                                    layer.close(index);
                                    window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
                                } else {
                                    layer.alert('出库失败！', {
                                        title: '提示框',
                                        icon: 2,
                                    });
                                }
                            }
                        })
                    }
                }
            });
        });
    });
</script>
<!--入库添加先跳产品交接单列表-->
<script>
    $(function () {
        $("#bb").on('click', function () {
            layer.open({
                type: 2,
                title: '未处理的交接单',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['1200px', '500px'],
                content: '/ioWarehouse/turnHandover/',
                btn: ['选择', '取消'],
                yes: function (index, layero) {
                    var div = $(layero).find("iframe").contents().find("#add_handover")
                    if (div.find(":checkbox:checked").length != 1) {
                        layer.alert("请选择一条交接单信息进行入库", {
                            title: '提示框',
                            icon: 0,
                        });
                        return false;
                    } else {
                        var d = {};
                        d.handoverId = div.find(":checkbox:checked").parent().parent().parent().children("td:eq(2)").text();
                        d.orderid = div.find(":checkbox:checked").parent().parent().parent().children("td:eq(3)").text();
                        d.wareName = div.find(":checkbox:checked").parent().parent().parent().children("td:eq(4)").text();
                        d.inType = div.find(":checkbox:checked").parent().parent().parent().children("td:eq(8)").text();
                        layer.close(index);
                        handover(d);
                    }
                }
            });
        });
        <!--入库添加的界面跳转-->
        function handover(d) {
            layer.open({
                type: 2,
                title: '添加入库单',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['1200px', '660px'],
                content: '/ioWarehouse/turnIn/?wName='+d.wareName+'&oNo='+d.orderid+'&handoverId='+d.handoverId+'&inType='+d.inType
            });
        }
    });

</script>
<!--详情的界面跳转代码-->
<script>
    $(function () {
        $("body").on('click','.property_list',function (obj) {
            var no = obj.currentTarget.parentElement.parentElement.children[1].textContent;
            console.log(no);
            layer.open({
                type: 2,
                title: '详情',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['1200px', '600px'],
                content: '/ioWarehouse/turnDetail?iomNo='+no,
                btn: ['返回'],
                yes: function (index, layero) {
                    layer.close(index);
                }
            });
        });
    });
</script>
<!--日期插件-->
<script>
    $(function () {
        laydate.render({
            elem: '#outTime',
            type: 'date'
        });
    })
</script>
<!--面包屑返回值-->
<script>
    $(function () {
        //面包屑返回值
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.iframeAuto(index);
        $('.Refund_detailed').on('click', function () {
            var cname = $(this).attr("title");
            var chref = $(this).attr("href");
            var cnames = parent.$('.Current_page').html();
            var herf = parent.$("#iframe").attr("src");
            parent.$('#parentIframe').html(cname);
            parent.$('#iframe').attr("src", chref).ready();
            ;
            parent.$('#parentIframe').css("display", "inline-block");
            parent.$('.Current_page').attr({"name": herf, "href": "javascript:void(0)"}).css({
                "color": "#4c8fbd",
                "cursor": "pointer"
            });
            //parent.$('.Current_page').html("<a href='javascript:void(0)' name="+herf+" class='iframeurl'>" + cnames + "</a>");
            parent.layer.close(index);
        });
    })
</script>

</body>
</html>
